
#include "PyrolysisGasADMaterial.h"

registerMooseObject("TrilobitaApp", PyrolysisGasADMaterial);

InputParameters
PyrolysisGasADMaterial::validParams()
{
    auto params = ADMaterial::validParams();

    params.addRequiredCoupledVar("temperature", "Coupled temperature");
    params.addRequiredCoupledVar("porepressure", "Coupled porepressure");
    params.addRequiredParam<std::vector<Real> >("viscosity_list", "The vector of pyrolysis gas viscosity values for building the piecewise function");
    params.addRequiredParam<std::vector<Real> >("viscosityT_list", "The vector of temperature values for building the piecewise function to compute pyrolysis gas viscosity");
    params.addRequiredParam<std::vector<Real> >("cpg_list", "The vector of pyrolysis gas specific heat values for building the piecewise function");
    params.addRequiredParam<std::vector<Real> >("cpgT_list", "The vector of temperature values for building the piecewise function to compute pyrolysis gas specific heat");
    return params;
}

PyrolysisGasADMaterial::PyrolysisGasADMaterial(const InputParameters& parameters)
    : ADMaterial(parameters),
    _temperature(coupledValue("temperature")),
    _porepressure(coupledValue("porepressure")),
    _rhog(declareADProperty<Real>("pyrolysis_gas_density")),
    _viscosity(declareADProperty<Real>("pyrolysis_gas_viscosity")),
    _gas_specific_heat(declareADProperty<Real>("pyrolysis_gas_specific_heat"))

{
    _viscosity_list = getParam<std::vector<Real>>("viscosity_list");
    _viscosityT_list = getParam<std::vector<Real>>("viscosityT_list");
    _func_viscosity_T = LinearInterpolation(_viscosityT_list, _viscosity_list);
    _cpg_list = getParam<std::vector<Real>>("cpg_list");
    _cpgT_list = getParam<std::vector<Real>>("cpgT_list");
    _func_cpg_T = LinearInterpolation(_cpgT_list, _cpg_list);
}

void
PyrolysisGasADMaterial::initQpStatefulProperties()
{
    Real R = 287;
  //  _rhog[_qp] = _porepressure[_qp] / R / (_temperature[_qp] + 1e-10);
    _rhog[_qp] = 1.6;
    _viscosity[_qp] = _func_viscosity_T.sample(_temperature[_qp]);
    _gas_specific_heat[_qp] = _func_cpg_T.sample(_temperature[_qp]);

 }


void
PyrolysisGasADMaterial::computeQpProperties()
{
    Real R = 287;
 //   _rhog[_qp] = _porepressure[_qp] / R / (_temperature[_qp] + 1e-10);
    _rhog[_qp] = 1.6;
    _viscosity[_qp] = _func_viscosity_T.sample(_temperature[_qp]);
    _gas_specific_heat[_qp] = _func_cpg_T.sample(_temperature[_qp]);
}